// import request from '@/utils/service'
import request from '@/utils/request'
import swaggerservice from '@/utils/swaggerservice'
import { getStore } from '@/utils/store.js'
import { encrypt } from '@/api/aesUtil.js'
import qs from 'qs'
export function apiComm(apicode, param) {
  return request({
    url: '/wxcomm/apiComm/' + apicode,
    method: 'post',
    data: param
  })
}
export function getNewId() {
  return request({
    url: '/wxcomm/getNewId',
    method: 'post',
    data: {}
  })
}
export function getListHeadCell(apicode) {
  return request({
    url: '/wxcomm/getListHeadCell/' + apicode,
    method: 'post'
  })
}
export function getApiFieldNames(param) {
  return request({
    url: '/wxcomm/getApiFieldNames',
    method: 'post',
    data: param
  })
}

export function getEnumDic(menuType) {
  return request({
    url: '/wxcomm/getDictionaryEnum?menuType=' + menuType,
    method: 'post'
  })
}

export function getBatchDictionaryEnum(param) {
  return request({
    url: '/wxcomm/getBatchDictionaryEnum',
    method: 'post',
    data: param
  })
}

export function ExportExlce(apicode, param) {
  return request({
    url: '/wxcomm/ExportExlce/' + apicode,
    method: 'post',
    data: param,
    responseType: 'blob'
  })
}
export function uploadfile(param) {
  return request({
    url: '/wxcomm/uploadfile',
    method: 'post',
    data: param
  })
}

export function uploadImg(param) {
  return request({
    url: '/wxcomm/uploadImg',
    method: 'post',
    data: param
  })
}
export function querySignature(param) {
  let signature = encrypt('{"modelType":"'+param+'","time":'+'"'+getCurrentTime()+'"}')
  return request({
    url: '/wxcomm/querySignature?modelType='+param,
    method: 'post',
    data: {"signature":signature}
  })
}

function getCurrentTime() {
  var date = new Date();//当前时间
  var year = date.getFullYear() //返回指定日期的年份
  var month = repair(date.getMonth() + 1);//月
  var day = repair(date.getDate());//日
  var hour = repair(date.getHours());//时
  var minute = repair(date.getMinutes());//分
  var second = repair(date.getSeconds());//秒

  //当前时间
  var curTime = year + "-" + month + "-" + day
          + " " + hour + ":" + minute + ":" + second;
  return curTime;
}

function repair(i){
  if (i >= 0 && i <= 9) {
      return "0" + i;
  } else {
      return i;
  }
}
export function getFromInfo(param) {
  return request({
    url: '/wxcomm/apiComm/getFromInfo',
    method: 'post',
    data: param
  })
}
export function getFromFidByIDNum(param) {
  return request({
    url: '/wxcomm/apiComm/getFromFidByIDNum',
    method: 'post',
    data: param
  })
}

export function getFromInfoList() {
  return request({
    url: '/wxcomm/apiComm/getFromInfoList',
    method: 'post',
    data: {}
  })
}
export function uploadOSSFile(ossurl,param) {
  return request({
    url: ossurl,
    method: 'post',
    data: param
  })
}

export function download(url) {
  return request({
    url: '/wxcomm/download?path=' + url,
    method: 'get'
  })
}

export function getSwagggerInfo(param) {
  return request({
    url: '/wxcomm/getSwagggerInfo',
    method: 'post',
    data: param
  })
}

export function ajaxComm(apicode, param) {
  let ajaxurl = '/wxcomm/apiComm/' + apicode
  if (param.$query !== undefined) {
    ajaxurl = ajaxurl + qs.stringify(param.$query)
  }
  if(apicode.indexOf('SaveDataInfo')!=-1)
  {
    if(param.body.openid==null||param.body.openid=='')
    {
      param.body.openid = localStorage.getItem("openId");
    }
    if(param.body.isimport==null||param.body.isimport=='')
    {
      param.body.isimport = '否';
    }
    param.body.auditflag = '未审核';

  }
  return request({
    url: ajaxurl,
    method: 'post',
    data: param.body
  })
}
export function then() {
  console.log(1)
}
export function ajaxswagger(url, param, method) {
  const swaggerconfig = getStore({ name: 'swaggerconfig' })
  if (swaggerconfig === null) {
    const returnobj = {}
    returnobj.then = then
    return returnobj
  }
  let ajaxurl = swaggerconfig.Apidoc + url
  if (param.$query !== undefined) {
    ajaxurl = ajaxurl + qs.stringify(param.$query)
  }
  return swaggerservice({
    url: ajaxurl,
    method: method === undefined ? 'post' : method,
    data: param.body
  })
}
